//{====================================================================================
//! @file Var2taskCotv.c
//! @date    2013-09-29 21:20
//! @author Andrianov Georgiy <egor.andrianov81@gmail.com>
//!
//! Programm calculate prime number with number n
//!
//! @par The programm number
//!      The programm outputs prime with this number
//}====================================================================================

#include <stdio.h>
#include <math.h>

long simpling(int k);

int main()
{
    int n = 0, simple = 0;
    printf("Input number of simple\n");
    scanf("%i", &n);
    simple = simpling(n);
    printf("%i is a simple number with number %i", simple, n);
    return 0;
}
/*
j - number of j-simle
prost - array of simple numbers

*/

//! simpling - calculate prime number with number n
//!
//! @param      n   number
//!
//! @return         prime with this number

long simpling(int k)
{
    int i = 0, j = 2, index = 0;
    long chiclo = 2;
    long prost[10000];
    prost[1] = 2;
    while(j < k + 1)
    {
    index = 0;
    chiclo++;
        for (i = 1; i < j; i++)
        {
            assert(0 < i && i < n);
            if (chiclo % prost[i] == 0)
            {
                index = 1;
            }
        }
    if (index == 0)
    {
        prost[j] = chiclo;
        //printf("This is # %i simple - %i\n", j, prost[j]);
        j++;
    }
    }
    return prost[k];
}
